package me.aartikov.screenresultsample;

import me.aartikov.alligator.*;
import me.aartikov.alligator.navigationfactories.NavigationFactory;
import ohos.aafwk.ability.AbilityPackage;
import ohos.app.ElementsCallback;
import ohos.global.configuration.Configuration;

public class SampleApplication extends AbilityPackage {
    private static OhosNavigator sOhosNavigator;
    private static long lastCLickTime = 0;
    private static SampleApplication instance;

    public static void setsOhosNavigator(OhosNavigator sOhosNavigator) {
        SampleApplication.sOhosNavigator = sOhosNavigator;
    }

    public static void setLastCLickTime(long lastCLickTime) {
        SampleApplication.lastCLickTime = lastCLickTime;
    }

    public static void setInstance(SampleApplication instance) {
        SampleApplication.instance = instance;
    }

    public static SampleApplication getInstance() {
        return instance;
    }

    public boolean doubleClick() {
        boolean isSingleClick = System.currentTimeMillis() - lastCLickTime < 500;
        if (!isSingleClick) {
            setLastCLickTime(System.currentTimeMillis());
        }
        return isSingleClick;
    }


    @Override
    public void onInitialize() {
        super.onInitialize();
        setInstance(this);
        setsOhosNavigator(new OhosNavigator(new SampleNavigationFactory()));
        registerCallbacks(AbilityStack.getInstance(), new ElementsCallback() {
            @Override
            public void onMemoryLevel(int i) {

            }

            @Override
            public void onConfigurationUpdated(Configuration configuration) {

            }
        });
    }

    public static Navigator getNavigator() {
        return sOhosNavigator;
    }

    public static NavigationFactory getNavigationFactory() {
        return sOhosNavigator.getNavigationFactory();
    }

    public static NavigationContextBinder getNavigationContextBinder() {
        return sOhosNavigator;
    }

    public static AbilityResultHandler getActivityResultHandler() {
        return sOhosNavigator.getActivityResultHandler();
    }
}
